/*
	订阅者：订阅主题，注册到发布者
*/
package amq

type Subscriber struct {
	Name    string
	Channel subChannel
}

// 新建订阅者
func NewSubscriber(name string, publisher *Publisher, topic string) *Subscriber {
	channel := make(subChannel)
	sub := &Subscriber{
		Name:    name,
		Channel: channel,
	}
	publisher.PublishTopic(topic, sub.Channel)
	return sub
}

// 获取信息
func (s *Subscriber) GetMsg(f func(msg interface{})) {
	for msg := range s.Channel {
		f(msg)
	}
}
